home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 17822 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.6 KB

  1. Path: helium.einet.net!usenet
  2. From: arisco@tradewave.com (John Arisco)
  3. Newsgroups: comp.os.ms-windows.programmer.tools.misc,comp.os.ms-windows.programmer.win32,comp.os.ms-windows.programmer.misc,comp.lang.c++
  4. Subject: Re: [Q] Why doesn't this compile?
  5. Date: Wed, 17 Apr 1996 18:24:07 GMT
  6. Organization: TradeWave Corporation
  7. Message-ID: <4l3cpv$l74@helium.einet.net>
  8. References: <317523C0.5042@eps.agfa.be>
  9. NNTP-Posting-Host: platinum.einet.net
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. Ranko Orlic <rorlic@eps.agfa.be> wrote:
  13.  
  14. >Using MSVC 4.0 compiler I get the following:
  15.  
  16. >File test.cpp: ---------------------------------
  17.  
  18. >class A {
  19. >public:
  20. >    class L {
  21. >    public:
  22. >        L() {}
  23. >        virtual void f() {
  24. >            int dummy = 0;
  25. >        }
  26. >    };
  27. >    A();
  28. >};
  29.  
  30. >class B : public A {
  31. >    class L : public A::L {
  32. >    public:
  33. >        L() {}
  34. >        virtual void f() {
  35. >            A::L::f();
  36. >        }
  37. >    };
  38. >    B();
  39. >};
  40.  
  41. >Compilation result: ----------------------------
  42.  
  43. >test.cpp(18) : error C2352: 'A::L::f' : illegal call of 
  44. >nonstatic member function
  45. >Error executing cl.exe.
  46. >test.obj - 1 error(s), 1 warning(s)
  47.  
  48. >------------------------------------------------
  49.  
  50. >Anybody knows what's wrong with it?
  51. >Thanks,
  52.  
  53. >-- Ranko.
  54.  
  55. You cannot call a non-static member function without specifying
  56. an object.  The way you've written this, there is no way for B::L::f()
  57. to set its "this" pointer.  Of course, if this is really what you want
  58.  
  59. to do, the declaration of B::L::f() is unnecessary, since B::L
  60.  inherits the A::L::f() virtual method from its base class.
  61.  
  62. |  John Arisco   <arisco@tradewave.com>
  63. |  TradeWave Corp, 3636 Executive Center Dr, #100, Austin, TX 78731
  64. |  Voice: (512) 433-5313     Main: 433-5300     Fax: 433-5303
  65.  
  66.  
  67.